import Vue from 'vue'
import Vuex from 'vuex'
import { getItem, setItem } from '@/utils/storage'
Vue.use(Vuex)


//避免访问和获取数据的名字不一致导致的问题
const USER_KRY = 'toutiao-user'
export default new Vuex.Store({
    state: {
        user: getItem(USER_KRY),
    },
    mutations: {
        setUser(state, data) {
            state.user = data

            setItem(USER_KRY, state.user)
        },
        //添加缓存页面
        // addCachePage(state, pageName) {
        //     if (!state.cachePages.includes(pageName)) {
        //         state.cachePages.push(pageName)
        //     }

        // },
        // //移除缓存页面
        // removeCachePage(state, pageName) {
        //     const index = state.cachePages.indexOf(pageName)
        //     if (index !== -1) {
        //         state.cachePages.splice(index, 1)
        //     }
        // }

    },
    actions: {

    }
})
